﻿@model int
@using Kojarskiy.Models
@using Kojarskiy.Core
@{
    var context = new Kojarskiy.Models.KojarskiyDbEntities();
    IQueryable<News> news;

        if (Model > 0)
        {
            news = context.News.Take(Model).OrderByDescending(x => x.NewsId);
        }
        else
        {
            news = context.News.OrderByDescending(x => x.NewsId);
        }        
}
@if(news.Any())
{
    foreach (var item in news)
    {
        <p style="clear: both;">
            <div class="f_r">@item.PublicationDate.Value.ToString("dd.MM.yyyy hh:mm")</div>
            <h4 style="text-decoration: underline;"><a href="@Url.Action("Details", "News", new {id = item.NewsId})" style="color: #311c0c;">@item.Name</a></h4>
            @if(item.Content.Contains("img"))
            {
                var links = item.Content.FetchImages();
                if(links != null && links.Count > 0)
                {
                    <img src="@Url.Content(links[0])" style="float: left; max-width: 150px; padding: 5px 5px 5px 0px;" />
                }
            }
            @item.Content.StripHtml().Substring(0, Math.Min(400, item.Content.StripHtml().Length)) ... <a href="@Url.Action("Details", "News", new {id = item.NewsId})" style="color: #311c0c; text-decoration: underline;">читать полностью</a>
        </p>
    }
}
else
{
        <div class="alert alert-info">В данном разделе нет материалов</div>
}